-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple models support #54
base: master
Are you sure you want to change the base?
Conversation
#any_login span#anylogin_back_to_user { | ||
#any_login span.anylogin_back_to_user { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed css id to class, because some login forms would be displayed.
def klass | ||
params[:as].constantize | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter is the login class (ex. User
, Staff
)
|
||
<span id="any_login_box"> | ||
<% AnyLogin.klasses.each do |klass| %> | ||
<%= form_tag any_login.sign_in_path(as: klass.to_s), :method => :post, :class => 'any_login_form' do %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set the login class here.
Hello @igorkasyanchuk @rbclark , Could you review this PR ? It was difficult to resolve conflicts on #44, so I created this new PR. |
@kenzo-tanaka good start, but I have a question, could you please extend at least dummy/devise app with another model? I want to try it on your branch. |
Thanks for the reply. I will try it. |
@igorkasyanchuk
I am having trouble understanding how to proceed this. |
Correct, specifically in the |
Thanks for the reply. I get an error when I run the following commands, is there a workaround? $ cd test/rails_apps/devise/
$ rails db:create
rails aborted!
NameError: uninitialized constant Bundler
/Users/tanakakenzou/Documents/personal/any_login/test/rails_apps/devise/config/application.rb:7:in `<top (required)>'
/Users/tanakakenzou/Documents/personal/any_login/test/rails_apps/devise/Rakefile:4:in `require_relative'
/Users/tanakakenzou/Documents/personal/any_login/test/rails_apps/devise/Rakefile:4:in `<top (required)>'
bin/rails:4:in `<main>'
Caused by:
LoadError: cannot load such file -- rails/commands
bin/rails:4:in `<main>'
(See full trace by running task with --trace) |
You just need to preface your commands with
|
@igorkasyanchuk @rbclark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! I had a few questions, mainly around the klass_name
and not breaking the API for existing users.
lib/any_login.rb
Outdated
mattr_accessor :klass_name | ||
@@klass_name = 'User' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this PR break the ability to use the old klass_name
style? If so it's likely going to require all users to update their configuration which is going to be a breaking change. Thoughts on just using klass_name
and checking whether it is an array or not in the code and then handling it accordingly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR does not break klass_name
style because the default value of klass_names
is [@@klass_name]
.
I think this is simpler than klass_name
, which accepts both strings and arrays.
If you want to use any_login in multiple models, you can use klass_names
, and if that is not necessary, you can continue to use klass_name
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can confirm that the klass_name
style is not broken in demo apps.
- test/rails_app/authlogic
- test/rails_app/clearance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a test in the demo devise application and it seems to confirm that klass_name
is currently broken. I switched the devise demo application to use klass_name = 'Staff'
and I was only presented with users and not staff:
Screen.Recording.2022-12-22.at.11.53.49.AM.mov
The reason this is happening it the klass_names
is always being initialized with the default value of klass_name
(which is User) and it is never taking into account the users input. The easiest way to fix this would be to just use klass_name
for everything and just handle it properly if klass_name
is an array.
Thank you @kenzo-tanaka, this is super close to being ready to merge. The only remaining issue is the |
9d13a77
to
9e40d23
Compare
Related: #44
This change will support multiple models.
What I fixed
klass_names
params[:as]
params[:as]
and login.Configuration
Demo
any_login_multiple.mov
I checked this behavior at this repository.
kenzo-tanaka/rails_sandbox#8